<?php

namespace Modules\Common\General\Login;


use Modules\Common\General\Notification\Sms\SmsVerifier;
use Modules\Common\Util\Api;

class BaseLoginController
{

    protected function loginByPassword($user)
    {

        if ($user->verifyPassword(request('password'))) {
            $token = $user->login();
            return Api::success(['token' => $token], '登录成功！');
        } else {
            return Api::fail('密码错误！');
        }
    }

    protected function loginByCode($user, $tag)
    {
        if (SmsVerifier::verify(request('mobile'), request('code'), $tag)) {
            $token = $user->login();
            return Api::success(['token' => $token], '登录成功！');
        } else {
            return Api::fail('验证码错误！');
        }
    }
}
